package com.ve.utils;
import android.content.*;
import android.content.pm.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;

public final class FileInfoUtils {
    public static boolean StringEmpty(String string) {
        return string == null || string.endsWith("") ;
    }

    /*
	 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
	 */
	public static float dp2px(Context context, float dpValue) {
		float scale =context.getResources().getDisplayMetrics().density;
		return dpValue * scale + 0.5f;
	}


	/*
	 * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
	 */
	public static float px2dp(Context context, float pxValue) {
		float scale = context.getResources().getDisplayMetrics().density;
		return pxValue / scale + 0.5f;
	}
	

	public static void copy(String content, Context context) {  
		ClipboardManager cmb = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);  
		cmb.setText(content.trim());  
	}  

	public static String paste(Context context) {  
		ClipboardManager cmb = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);  
		return cmb.getText().toString().trim();  
	} 

    public static Bitmap drawableToBitmap(Drawable drawable) {
        int n = drawable.getIntrinsicWidth();
        int n2 = drawable.getIntrinsicHeight();
        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
        Bitmap bitmap = Bitmap.createBitmap(n, n2, config);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
	public static Drawable bitmapToDrawable(Bitmap bitmap) {
		return new BitmapDrawable(bitmap);
	}
    public static Bitmap getApkThumbnail(Context context, String string) {
		PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageArchiveInfo(string, PackageManager.GET_ACTIVITIES);
        if (packageInfo != null) {
            ApplicationInfo applicationInfo = packageInfo.applicationInfo;
            applicationInfo.sourceDir = string;
            applicationInfo.publicSourceDir = string;
            return drawableToBitmap(applicationInfo.loadIcon(packageManager));
		}
//        App.skin.fileIcons[File.TYPE_PACKAGE]
		return null;
	}
    public static Bitmap getImageThumbnail(String string, int w, int h) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(string, options);
        options.inJustDecodeBounds = false;
        int dw = options.outWidth / w;
        int dh = options.outHeight / h;
        if (dw >= dh) {
            dw = dh;
        }
        if (dw <= 0) {
            dw = 1;
        }
        options.inSampleSize = dw;
        return ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(string, options), w, h, 2);
    }


    public static Bitmap getVideoThumbnail(String path, int w, int h, int t) {
		Bitmap bitmap;
		bitmap = ThumbnailUtils.createVideoThumbnail(path, t);
		return ThumbnailUtils.extractThumbnail(bitmap, w, h, 2);

    }




}


